<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button type="primary" icon="el-icon-plus" v-auth="'fa_user.create'" @click="create"></el-button>

                <el-button type="primary" icon="el-icon-plus" v-auth="'fa_user.create2'" @click="create2">添加售后站</el-button>
                <el-button type="danger" plain icon="el-icon-delete" v-auth="'fa_user.delete'" v-if="selection.length>0" :disabled="selection.length==0" @click="dels"></el-button>
            </div>

        
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search" placeholder="搜索" @clear="this.$TABLE.searchSubmit(this)" clearable></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="this.$TABLE.searchSubmit(this)"></el-button>
                    <imiFilterBar :options="options" @filterChange="filterChange"></imiFilterBar>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" row-key="id" :apiObj="apiObj" :params="params" @selection-change="selectionChange" @cell-dblclick="doubleClick" stripe remoteSort remoteFilter>
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="ID" prop="id" >
                                    
				</el-table-column>
                <el-table-column label="组别ID" prop="group_id" >
                                    
				</el-table-column>
                <el-table-column label="用户名" prop="username" >
                                    
				</el-table-column>

                <el-table-column label="角色ID" prop="set_id" >
                    <template #default="scope"  >
                    <el-tag >{{set_id_option[scope.row.set_id]}} </el-tag>
                    </template> 
				</el-table-column>

                <el-table-column label="运营中心" prop="run_id" >
                    <template #default="scope"  >
                    <el-tag >{{rundataList[scope.row.run_id]}} </el-tag>
                    </template>     
				</el-table-column>
                
                <el-table-column label="昵称" prop="nickname" >
                                    
				</el-table-column>
                <el-table-column label="真实名" prop="name" >
                                    
				</el-table-column>
                <el-table-column label="手机号" prop="mobile" >
                                    
				</el-table-column>
                <el-table-column label="身份证号" prop="sfz" >
                                    
				</el-table-column>
                <el-table-column label="联系住址" prop="address" >
                                    
				</el-table-column>
                <el-table-column label="身份证正面" prop="sfz1_image" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.sfz1_image" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="身份证反面" prop="sfz2_image" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.sfz2_image" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="人像照" prop="sfz3_image" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.sfz3_image" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="实名状态" prop="real_status" >
                                    
				</el-table-column>
                <el-table-column label="头像" prop="avatar" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.avatar" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="性别" prop="gender" >
                                    
				</el-table-column>
                <el-table-column label="生日" prop="birthday" >
                                    
				</el-table-column>
                <el-table-column label="格言" prop="bio" >
                                    
				</el-table-column>
                <el-table-column label="余额" prop="money" >
                                    
				</el-table-column>
                <el-table-column label="贝壳" prop="shell" >
                                    
				</el-table-column>
                <el-table-column label="保证金" prop="surety" >
                                    
				</el-table-column>
                <el-table-column label="邀请成功总积分" prop="share_score" >
                                    
				</el-table-column>
                <el-table-column label="积分" prop="score" >
                                    
				</el-table-column>
                <el-table-column label="加入IP" prop="joinip" >
                                    
				</el-table-column>
                <el-table-column label="加入时间" prop="jointime"  align="right" width="180" :formatter="this.$TABLE.datetime">
                                    
				</el-table-column>
                <el-table-column label="状态" prop="status" >
                                    
				</el-table-column>
                <el-table-column label="验证" prop="verification" >
                                    
				</el-table-column>
                <el-table-column label="上级id" prop="pid" >
                                    
				</el-table-column>
                <el-table-column label="二维码" prop="qr" >
                    <template #default="scope">
                    <el-avatar :src="scope.row.qr" size="small"></el-avatar>
                    </template>                
				</el-table-column>
                <el-table-column label="邀请码" prop="invite_code" >
                                    
				</el-table-column>

                <el-table-column label="默认地址" prop="addr_id" >
                                    
				</el-table-column>
     
                <el-table-column label="省id" prop="province_id" >
                                    
				</el-table-column>
                <el-table-column label="城市id" prop="city_id" >
                                    
				</el-table-column>
                <el-table-column label="区id" prop="district_id" >
                                    
				</el-table-column>
                <el-table-column label="乡镇id" prop="town_id" >
                                    
				</el-table-column>
                
                <el-table-column label="操作" fixed="right" align="right" width="140">
                    <template #default="scope">
                        <el-button type="text" v-auth="'fa_user.update'" size="small" @click="update(scope.row)">编辑
                        </el-button>
                        <el-popconfirm title="确定删除吗？" @confirm="del(scope.row)">
                            <template #reference>
                                <el-button type="text" v-auth="'fa_user.delete'" size="small">删除</el-button>
                            </template>
                        </el-popconfirm>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>
    </el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
    <save-dialog2 v-if="dialog.save" ref="saveDialog2" @success="handleSuccess" @closed="dialog.save=false"></save-dialog2>
</template>
<script>
    import saveDialog from './save';
    import saveDialog2 from './save2';
    import imiFilterBar from '@/components/imiFilterBar';
    export default {
        name: 'fa_user',
        components: {
            saveDialog,
            saveDialog2,
            imiFilterBar
        },
        data() {
            return {
                options: [
                    {
                        label: 'ID',
                        value: 'id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '组别ID',
                        value: 'group_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '用户名',
                        value: 'username',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '昵称',
                        value: 'nickname',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '真实名',
                        value: 'name',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '手机号',
                        value: 'mobile',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '身份证号',
                        value: 'sfz',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '联系住址',
                        value: 'address',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '实名状态',
                        value: 'real_status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '等级',
                        value: 'level',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '性别',
                        value: 'gender',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '生日',
                        value: 'birthday',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '格言',
                        value: 'bio',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '余额',
                        value: 'money',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '贝壳',
                        value: 'shell',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '保证金',
                        value: 'surety',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '邀请成功总积分',
                        value: 'share_score',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '积分',
                        value: 'score',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '连续登录天数',
                        value: 'successions',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '最大连续登录天数',
                        value: 'maxsuccessions',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '上次登录时间',
                        value: 'prevtime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '登录时间',
                        value: 'logintime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '登录IP',
                        value: 'loginip',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '失败次数',
                        value: 'loginfailure',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '加入IP',
                        value: 'joinip',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '加入时间',
                        value: 'jointime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '创建时间',
                        value: 'createtime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: '更新时间',
                        value: 'updatetime',
                        type: 'datetimerange',
                        operator: 'between',
                    },
					{
                        label: 'Token',
                        value: 'token',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '状态',
                        value: 'status',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '验证',
                        value: 'verification',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '上级id',
                        value: 'pid',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '变更前上级',
                        value: 'before_pid',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '原上级',
                        value: 'old_pid',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '密码',
                        value: 'cipher',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '二维码',
                        value: 'qr',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '邀请码',
                        value: 'invite_code',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '运营中心',
                        value: 'run_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '默认地址',
                        value: 'addr_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '角色ID',
                        value: 'set_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '技能介绍',
                        value: 'skill',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '省id',
                        value: 'province_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '城市id',
                        value: 'city_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '区id',
                        value: 'district_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '乡镇id',
                        value: 'town_id',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '支付密码',
                        value: 'pay_password',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '开放平台',
                        value: 'unionid',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '微信真实姓名',
                        value: 'wechat_name',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '微信openid',
                        value: 'wechat_openid',
                        type: 'text',
                        operator: '=',
                    },
					{
                        label: '售后站服务用户id',
                        value: 'after_sales_user_id',
                        type: 'text',
                        operator: '=',
                    },
					                    
                ],
                dialog: {
                    save: false
                },
                apiObj: this.$API.fa_user.read,
                selection: [],
                search: '',
                params:{},
                set_list_option:[],
                rundataList:[],
            }
        },
        created() {
            this.$TABLE.setFilterValue(this);
            this.getrundataList();
        },
        mounted() {
            this.getStore();//表格加载时会执行该方法
        },
        methods: {
            async getrundataList(){
                var res = await this.$API.run.read.get({page: 1,pageSize: 999999});
                var list = res.data.list;
                var cate = [];
                for (let index = 0; index < list.length; index++) {
                    cate[list[index].id] = list[index].name;                    
                }
                console.log(cate);
                this.rundataList = cate;
            },
            async getStore(){//需要加入的方法
                
                var res = await this.$API.set.read.get();
                var list = res.data.list;
                var set_list_option = [];
                for (let index = 0; index < list.length; index++) {
                    set_list_option[list[index].id] = list[index].name;                    
                }
                console.log(set_list_option);
                this.set_id_option = set_list_option;
            },
            doubleClick(row) {
                this.update(row);
            },
            filterChange(data) {
                this.$TABLE.filter(data, this);
            },
            create() {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open()
                })
            },

            create2() {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog2.open()
                })
            },
            update(row) {
                this.dialog.save = true
                this.$nextTick(() => {
                    this.$refs.saveDialog.open('update').setData(row)
                })
            },
            async del(row) {
                var res = await this.$API.fa_user.delete.post({ids: row.id});
                if (res.code == 200) {
                    this.$refs.table.refresh()
                    this.$message.success(res.message)
                } else {
                    this.$alert(res.message, "提示", {type: 'error'})
                }
            },
            async dels() {
                if (!this.selection.length) {
                    this.$message.warning("请选择要删除的数据")
                    return false;
                }
                var ids = [];
                for (const i in this.selection) {
                    ids.push(this.selection[i].id)
                }
                this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
                    type: 'warning'
                }).then(() => {
                    const loading = this.$loading();
                    this.$API.fa_user.delete.post({ids:ids}).then(res => {
                        if (res.code == 200) {
                            this.$refs.table.refresh()
                            this.$message.success(res.message)
                        } else {
                            this.$message.error(res.message)
                        }
                        loading.close();
                    });
                })
            },
            selectionChange(selection) {
                this.selection = selection;
            },
            handleSuccess() {
                this.$refs.table.refresh()
            }
        }
    }
</script>